import { createSlice,createAsyncThunk } from "@reduxjs/toolkit";
import {findById} from "../../services/shops"
// 中间件 专门做异步的
export const fetchShops=createAsyncThunk('shops/fetchShops',async(id) => {
  let {data}=await findById(id);
  console.log(data,'sata');
  return data;
})

const shopsSlice = createSlice({
  name: "shops",
  initialState:{
      updateVisable: false,
      // aa:'',
      shops:{
        types:{},
        shopImg:[]
      } //这里与下面state.student 的名字一样，这里改变下面也要改变
    },
  reducers: {
      setupdate(state,action){
        state.updateVisable =action.payload;
      },
      setShop(state,action){
        state.shops =action.payload;
      },

  },
  extraReducers(builder) { 
    builder.addCase(fetchShops.fulfilled, 
    (state, action) => { state.shops = action.payload; }) }
});
// 
export const {setupdate,setShop}=shopsSlice.actions;
export default shopsSlice.reducer;